#pragma once
#include"KuGouApi.h"
#include"OnlionMusicInfo.h"
#include<JsonKeysConfig.h>
#include<qurl.h>
#include<memory>
#include<qobject.h>
#include<qlist.h>

struct Song;
class QNetworkAccessManager;
class QNetworkReply;

//Must set configKeys
class KuGouMusicManager:public QObject
{
	Q_OBJECT
private:
	std::unique_ptr<KuGouApi> m_api;
	QNetworkAccessManager* m_manager;
	JsonKeysConfig m_config;
	QList<QNetworkReply* > m_replies;
public:
	KuGouMusicManager(std::unique_ptr<KuGouApi> apiSource, QObject* parent = nullptr);
	KuGouMusicManager(const JsonKeysConfig& config,
		std::unique_ptr<KuGouApi> apiSource,
		QObject* parent = nullptr);

	KuGouMusicManager();
	void searchSong(
		const JsonKeysConfig& retJsonKeys,
		const QString& songName ,
		int pageSize = 30,
		int searchPage = 1		
	);

	void searchSong(
		const JsonKeysConfig& retJsonKeys,
		const JsonKeysConfig& urlRetJsonKeys,
		const QString& songName ,
		int pageSize = 30,
		int searchPage = 1		
	);
	void searchSong(
		const QString& songName,
		int pageSize = 30,
		int searchPage = 1
	);
	void setJsonKeysConfig(const JsonKeysConfig& config);
	void getSongUrl (const JsonKeysConfig retJsonKeys, const QString songHash);
	void getSongUrl(const JsonKeysConfig retJsonKeys, const QStringList hashList);
	void downloadSong(QUrl url, const QString& singerName, const QString& songName,const QString& fileType = "mp3");
	void setApi(std::unique_ptr<KuGouApi> apiSource);
	
signals:
	void searchFinished(const QList<OnlionMusicInfo>& ans);
	void getUrl(QUrl songUrl);
	void getUrl(QList<QUrl> url);
	void downloadSongFinished();
	void downloadSongFailed(const QString& errStr);
};

